/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2017
 */

package com.database.management.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.database.management.dao.jpa.DbConnectionRepository;
import com.database.management.domain.DbConnection;
import com.database.management.service.IDbConnectionService;

@Service
public class DbConnectionServiceImpl implements IDbConnectionService {
	private Logger log = LoggerFactory.getLogger(DbConnectionServiceImpl.class);

	@Autowired
	private DbConnectionRepository dbConnectionRepository;

	@Override
	public void delete(Integer id) {
		dbConnectionRepository.delete(id);
	}

	@Override
	public DbConnection insert(DbConnection record) {
		return dbConnectionRepository.save(record);
	}

	@Override
	public DbConnection update(DbConnection record) {
		return dbConnectionRepository.saveAndFlush(record);
	}

	@Override
	public DbConnection findOne(Integer id) {
		return dbConnectionRepository.findOne(id);
	}

	@Override
	public List<DbConnection> findAll(Example<DbConnection> example, Sort sort) {
		if (example.getProbe() == null) {
			return dbConnectionRepository.findAll(sort);
		} else {
			return dbConnectionRepository.findAll(example, sort);
		}
	}

	@Override
	public Page<DbConnection> findPage(Example<DbConnection> example, Pageable pageable) {
		if (example == null) {
			return dbConnectionRepository.findAll(pageable);
		} else {
			return dbConnectionRepository.findAll(example, pageable);
		}
	}

}
